package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-03 11:07
 **/
public class _22_链表中倒数第K个结点 {

    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode current = head;
        while (current != null && k >0) {
            current = current.next;
            k--;
        }
        if(k > 0) {
            return null;
        }
        while (current != null) {
            current = current.next;
            head = head.next;
        }
        return head;

    }
}
